﻿using HSJM.Service.MWS.Core;
using HSJM.Service.MWS.Core.ShareMode;
using HSJM.Service.MWS.Infrastructure.Dapper;
using StackExchange.Redis;
using System;
using System.Collections.Generic;
using System.Data;
using System.Text;
using System.Threading.Tasks;

namespace HSJM.Service.MWS.Infrastructure
{
    public interface IBaseDomain<T, TCondition> where T : IEntity
    {
        /// <summary>
        /// 获取事物
        /// </summary>
        /// <returns></returns>
        IDbTransaction GetTransaction();


        #region 查询
        /// <summary>
        /// 根据ID查询
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        Task<T> GetAsync(long id);

        /// <summary>
        /// 查询
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="sql"></param>
        /// <param name="param"></param>
        /// <param name="commandType"></param>
        /// <returns></returns>
        Task<IEnumerable<T>> GetListAsync(object param = null, string sql = null, CommandType? commandType = null);

        /// <summary>
        /// 查询
        /// </summary>
        /// <param name="condition"></param>
        /// <returns></returns>
        Task<IEnumerable<T>> GetListAsync(TCondition condition);

        /// <summary>
        /// 分页查询
        /// </summary>
        /// <param name="sql"></param>
        /// <param name="pageIndex"></param>
        /// <param name="pageSize"></param>
        /// <param name="param"></param>
        /// <returns></returns>
        PagedResult<T> GetPageList(int pageIndex, int pageSize, string sql=null, object param = null);
        #endregion

        #region 新增

        /// <summary>
        /// 批量新增
        /// </summary>
        /// <param name="list"></param>
        Task<HttpResponseResultModel<bool>> InsertBatch(List<T> list);

        /// <summary>
        /// 添加行数据
        /// </summary>
        /// <param name="entity"></param>
        /// <param name="dbTransaction"></param>
        /// <returns></returns>
        Task<HttpResponseResultModel<bool>> InsertAsync(T entity, IDbTransaction dbTransaction = null);
        #endregion

        #region 修改

        /// <summary>
        /// 修改(事物)
        /// </summary>
        /// <param name="entity"></param>
        /// <param name="dbTransaction"></param>
        /// <returns></returns>
        Task<HttpResponseResultModel<bool>> UpdateAsync(T entity, IDbTransaction dbTransaction = null);
        #endregion

        #region 删除

        /// <summary>
        /// 删除（事物）
        /// </summary>
        /// <param name="entity"></param>
        /// <param name="isDel">是否硬删除（默认软删除）</param>
        /// <param name="dbTransaction"></param>
        Task<HttpResponseResultModel<bool>> DeleteAsync(T entity,bool isDel=false, IDbTransaction dbTransaction = null);

        /// <summary>
        /// 批量删除
        /// </summary>
        /// <param name="entity"></param>
        Task<HttpResponseResultModel<bool>> DeleteBatch(List<T> list);
        #endregion

        #region SQL条件
        /// <summary>
        /// sql拼接条件
        /// </summary>
        /// <param name="parameter"></param>
        /// <param name="sqlStr"></param>
        /// <returns></returns>
       abstract string TrunConditionToSql(TCondition condition);
        #endregion
    }
}
